package b4.config
{
	import b4.model.vo.player.Obj;
	
	public class Config
	{
		//外观信息
		public static var appearanceConfigs:Object = new Object();
		//物品信息
		public static var objConfigs:Object = new Object();
		//城镇信息
		public static var townConfigs:Object = new Object();
		
		public static function parseXML(dataXML:XML):void
		{
			switch (parseInt(dataXML.fileType))
			{
				case 0:
					parseMainXML(dataXML);
				break;
				case 1:
					parseTownXML(dataXML);
				break;
			}
		}
		
		private static function parseMainXML(dataXML:XML):void
		{
			//解析外观信息
			for (var i:int = 0; i < dataXML.appearanceInfo.appearance.length(); i++)
			{
				var appearanceStr:String = dataXML.appearanceInfo.appearance[i];
				var appearanceStrs:Array = appearanceStr.split("\n");
				for (var j:int = 0; j < appearanceStrs.length; j++)
				{
					var itemStrs:Array = appearanceStrs[j].split(",");
					if (itemStrs.length > 1)
					{
						var appearanceConfig:AppearanceConfig = new AppearanceConfig(itemStrs);
						appearanceConfigs[appearanceConfig.index] = appearanceConfig;
					}
				}
			}
			//解析装备信息
			for (i = 0; i < dataXML.equipInfo.equip.length(); i++)
			{
				var equipStr:String = dataXML.equipInfo.equip[i];
				var equipStrs:Array = equipStr.split("\n");
				for (j = 0; j < equipStrs.length; j++)
				{
					itemStrs = equipStrs[j].split(",");
					if (itemStrs.length > 1)
					{
						var equipConfig:EquipConfig = new EquipConfig(itemStrs);
						objConfigs[equipConfig.index] = equipConfig;
					}
				}
			}
			//解析物品信息
			for (i = 0; i < dataXML.objInfo.obj.length(); i++)
			{
				var objStr:String = dataXML.objInfo.obj[i];
				var objStrs:Array = objStr.split("\n");
				for (j = 0; j < objStrs.length; j++)
				{
					itemStrs = objStrs[j].split(",");
					if (itemStrs.length > 1)
					{
						var objConfig:ObjConfig = new ObjConfig(itemStrs);
						objConfigs[objConfig.index] = objConfig;
					}
				}
			}
			//解析怪物信息
			for (i = 0; i < dataXML.creatureInfo.creature.length(); i++)
			{
				var creatureStr:String = dataXML.creatureInfo.creature[i];
				var creatureStrs:Array = creatureStr.split("\n");
				for (j = 0; j < creatureStrs.length; j++)
				{
					itemStrs = creatureStrs[j].split(",");
					if (itemStrs.length > 1)
					{
						var creatureConfig:CreatureConfig = new CreatureConfig(itemStrs);
						objConfigs[creatureConfig.index] = creatureConfig;
					}
				}
			}
			//解析地图信息
			for (i = 0; i < dataXML.mapInfo.map.length(); i++)
			{
				var mapStr:String = dataXML.mapInfo.map[i];
				var mapStrs:Array = mapStr.split("\n");
				for (j = 0; j < mapStrs.length; j++)
				{
					itemStrs = mapStrs[j].split(",");
					if (itemStrs.length > 1)
					{
						var townConfig:TownConfig = new TownConfig(itemStrs);
						townConfigs[townConfig.index] = townConfig;
					}
				}
			}
		}
		
		private static function parseTownXML(dataXML:XML):void
		{
			var index:int = parseInt(dataXML.index);
			//解析地图信息
			var townConfig:TownConfig = townConfigs[index];
			if (townConfig != null)
			{
				townConfig.loadDataXML(dataXML);
			}
			else
			{
				townConfig = new TownConfig();
				townConfig.loadDataXML(dataXML);
				townConfigs[townConfig.index] = townConfig;
			}
		}
	}
}